package com.leetcode.No0849;

/**
 * @program: leetcode
 * @description:
 * @author: wangzhihua
 * @date: 2023-08-28
 */
public class Solution {
	public int maxDistToClosest(int[] seats) {
		int zeroNum = 0;
		int result = 0;
		for (int i = 0; i < seats.length; ++i) {
			if (seats[i] == 1) {
				result = Math.max(result, ((zeroNum - 1) / 2) + 1);
				zeroNum = 0;
			} else {
				++zeroNum;
			}
		}
		if (zeroNum > 0) {
			result = Math.max(result, zeroNum);
		}
		zeroNum = 0;
		for (int i = seats.length - 1; i >= 0; --i) {
			if (seats[i] == 1) {
				result = Math.max(result, ((zeroNum - 1) / 2) + 1);
				zeroNum = 0;
			} else {
				++zeroNum;
			}
		}
		if (zeroNum > 0) {
			result = Math.max(result, zeroNum);
		}
		return result;
	}
}
